home *** CD-ROM | disk | FTP | other *** search
/ Nejlepší hry / Nejlepsi hry.iso / hry / sea of chaos / sea_install.msi / _15C39AAA7726369D39812BD40F01CF6A / _E53E635DC86847C1BDEF1657983CC5D4 < prev    next >
Text File  |  2005-04-19  |  1KB  |  58 lines

  1. //basic particle shader
  2. //rotates particles as they rise
  3. //input should be 4 points that are the same, tex coord will expand them in screen space
  4. //3rd component of tex coord is size of particle
  5. //Luke Lenhart
  6. //(C)2004-2005 Digipen Institute of Technology
  7.  
  8. //view,projection transform
  9. float4x4 matViewProj;
  10.  
  11. //camera position in world space
  12. float4 cameraPos;
  13.  
  14. //base position of emitter
  15. //float3 basePos;
  16.  
  17. //shader input
  18. struct VS_INPUT
  19. {
  20.     float4 Pos : POSITION;
  21.     float4 Color : COLOR;
  22.     float3 Tex0 : TEXCOORD0;
  23. };
  24.  
  25. //shader output
  26. struct VS_OUTPUT
  27. {
  28.     float4 Pos : POSITION;
  29.     float4 Color : COLOR;
  30.     float2 Tex0 : TEXCOORD0;
  31. };
  32.  
  33. //shader code
  34. VS_OUTPUT VShader(VS_INPUT In)
  35. {
  36.     VS_OUTPUT Out;
  37.     
  38.     //transform pos and copy tex coord and color over
  39.     Out.Pos=mul(matViewProj,In.Pos);
  40.     Out.Tex0.xy=In.Tex0.xy;
  41.     Out.Color=In.Color;
  42.     
  43.     float2 posOffset=In.Tex0-0.5f;
  44.     
  45.     //calc rotation matrix based on in component
  46.     float theta=dot(In.Pos,float3(0.2f,0.2f,0.2f))+(2.0f + 1.0f / In.Pos.z)*4.0f;
  47.     float2x2 matRot={cos(theta),sin(theta),-sin(theta),cos(theta)};
  48.     posOffset=mul(matRot,posOffset);
  49.     
  50.     //expand outwards from center point, based on distance and tex coord
  51.     float dist=distance(cameraPos.xyz,In.Pos.xyz);
  52.     
  53.     Out.Pos.xy+=(1.0f/sqrt(dist))*posOffset*In.Tex0.z;
  54.  
  55.     //spit out the results
  56.     return Out;
  57. }
  58.